﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data ;
using System.Data .SqlClient ;
using dhDataAcess.dataAcess .sysDataSetTableAdapters ;
using dhDataAcess.Model ;

namespace dhDataAcess.sysDAL
{
   public class moduleListDAL
    {
         private SqlTransaction tran = null;
        private SqlConnection conn = null;
        public moduleListDAL(SqlTransaction _transaction, SqlConnection _conn)
        {
            tran = _transaction;
            conn=_conn;
        }
      
        /// <summary>
        /// 插入一行程序模块表数据
        /// </summary>
        /// <param name="deptRow"></param>
        /// <returns></returns>

        public int moduleListInsert(moduleListModel deptRow)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            string insertStr = "insert into moduleList (mark,createDate,moduleType,moduleName,moduleNum) values(@mark,@createDate,@moduleType,@moduleName,@moduleNum)";

            SqlParameter[] para = {
                                   new SqlParameter ("@mark",deptRow .mark ),
                                   new SqlParameter ("@createDate",deptRow .createDate ),
                                   new SqlParameter ("@moduleType",deptRow.moduleType),
                                   new SqlParameter ("@moduleName",deptRow .moduleName),
                                   new SqlParameter ("@moduleNum",deptRow .moduleNum)
                                  };

            cmd.Parameters.AddRange(para);
            cmd.CommandText = insertStr;
            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }

        /// <summary>
        /// 更新一行程序模块表数据 
        /// </summary>
        /// <param name="deptRow"></param>
        /// <returns></returns>

        public int moduleListUpdate(moduleListModel deptRow)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            string updateStr = "update moduleList set mark=@mark,createDate=@createDate,moduleType=@moduleType,moduleName=@moduleName where moduleNum=@moduleNum";

            SqlParameter[] para = {
                                   new SqlParameter ("@mark",deptRow .mark ),
                                   new SqlParameter ("@createDate",deptRow .createDate ),
                                   new SqlParameter ("@moduleType",deptRow.moduleType),
                                   new SqlParameter ("@moduleName",deptRow .moduleName),
                                   new SqlParameter ("@moduleNum",deptRow .moduleNum)
                                  };
           
            cmd.Parameters.AddRange(para);
            cmd.CommandText = updateStr;
            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }


        /// <summary>
        /// 删除一行程序模块表数据
        /// </summary>
        /// <param name="moduleNum"></param>
        /// <returns></returns>
 
        public int moduleListDel(string moduleNum)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            string deleteStr = "delete moduleList where moduleNum=@moduleNum";
            SqlParameter[] para = {
                                new SqlParameter ("@moduleNum",moduleNum)
                              };

            cmd.Parameters.AddRange(para);
            cmd.CommandText = deleteStr;
            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }
        /// <summary>
        /// 根据模块编号返回模块名称
        /// </summary>
        /// <param name="moduleNum"></param>
        /// <returns></returns>

        public string moduleListretName(string moduleNum)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            string selectStr = "selete moduleName from moduleList where moduleNum=@moduleNum";
            SqlParameter[] para = {
                                new SqlParameter ("@moduleNum",moduleNum),
                              };

            cmd.Parameters.AddRange(para);
            cmd.CommandText = selectStr;
            cmd.Transaction = tran;
            SqlDataReader rdr = cmd.ExecuteReader();
            string moduleName = null;
            while (rdr.Read())
            {
                moduleName = rdr[0].ToString();
            }

            return moduleName;
        }


        public string moduleListSql(string moduleNum)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            string selectStr = "selete mark from moduleList where moduleNum=@moduleNum";
            SqlParameter[] para = {
                                new SqlParameter ("@moduleNum",moduleNum),
                              };

            cmd.Parameters.AddRange(para);
            cmd.CommandText = selectStr;
            cmd.Transaction = tran;
            SqlDataReader rdr = cmd.ExecuteReader();
            string moduleName = null;
            while (rdr.Read())
            {
                moduleName = rdr[0].ToString();
            }

            return moduleName;
        }
    }
}
